//
//  AddBuddyViewController.m
//  结伴
//
//  Created by mo on 16/8/9.
//  Copyright © 2016年 aleven. All rights reserved.
//

#import "AddBuddyViewController.h"
#import "AddBuddyTableViewCell.h"
#import "MyTableViewCell.h"
#import "AddBuddyTableViewCellTwo.h"
#import "AddBuddyTableViewCellThree.h"
#import "AddBuddyFooter.h"

@interface AddBuddyViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView_main;

@property (nonatomic,strong)NSString *str;

@end

@implementation AddBuddyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    AddBuddyFooter *footer = [[[NSBundle mainBundle] loadNibNamed:@"AddBuddyFooter" owner:nil options:nil] lastObject];
    [footer.button_main setTitle:@"完成" forState:UIControlStateNormal];
    
    footer.addBuddyFooter = ^(){
        
        
    };
    
    self.tableView_main.tableFooterView = footer;
    
    self.title = @"添加结伴";
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    NSInteger row = 2;
    if (section == 2) {
        row = 3;
    }
    
    return row;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CGFloat height = 50;
    if (indexPath.section == 2) {
        if (indexPath.row == 0) {
            height = 300;
        }else {
            height = 120;
        }
    }
    
    return height;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    id cell;
    static NSString *ID_main = @"AddBuddyTableViewCell";
    static NSString *ID_cells = @"MyTableViewCell";
    static NSString *ID_cellTwo = @"AddBuddyTableViewCellTwo";
    static NSString *ID_cellThree = @"AddBuddyTableViewCellThree";
    
    
    AddBuddyTableViewCell *cellOne = [tableView dequeueReusableCellWithIdentifier:ID_main];
    if (!cellOne) {
        cellOne = [[[NSBundle mainBundle] loadNibNamed:ID_main owner:nil options:nil] lastObject];
        
    }
    
    MyTableViewCell *cells = [tableView dequeueReusableCellWithIdentifier:ID_cells];
    if (!cells) {
        cells = [[[NSBundle mainBundle] loadNibNamed:ID_cells owner:nil options:nil] lastObject];
        
    }
    
    AddBuddyTableViewCellTwo *cellTwo = [tableView dequeueReusableCellWithIdentifier:ID_cellTwo];
    if (!cellTwo) {
        cellTwo = [[[NSBundle mainBundle] loadNibNamed:ID_cellTwo owner:nil options:nil] lastObject];
        
    }
    
    AddBuddyTableViewCellThree *cellThree = [tableView dequeueReusableCellWithIdentifier:ID_cellThree];
    if (!cellThree) {
        cellThree = [[[NSBundle mainBundle] loadNibNamed:ID_cellThree owner:nil options:nil] lastObject];
        
    }
    
    
    
    if (indexPath.section == 0) {
        
        if (indexPath.row == 0) {
            
            cellOne.textField_main.placeholder = @"请输入出发地";
            cellOne.iconName.image = [UIImage imageNamed:@"001"];
            
        }else{
            
            cellOne.textField_main.placeholder = @"请输入目的地 (多目的地用空格隔开";
            cellOne.iconName.image = [UIImage imageNamed:@""];
            
        }
        
           cellOne.textField_main.delegate = self;
        cell = cellOne;
   
    }else if (indexPath.section == 1) {
        
        if (indexPath.row == 0) {
            
            cells.iconName.image = [UIImage imageNamed:@""];
            cells.contentLabel.text = @"日期";
            
        }else{
            
            cells.iconName.image = [UIImage imageNamed:@""];
            cells.contentLabel.text = @"约伴人数";
            
        }
        
        cell = cells;
        
    }else{
        
        if (indexPath.row == 0) {
            cell = cellTwo;
        }else{
            
            cell = cellThree;
        }
    }
    
    
    return cell;
    
}

//结束编辑的时候调用

-(void)textFieldDidEndEditing:(UITextField *)textField{
    
    _str = textField.text;
    
}

//点击Return键的时候，（标志着编辑已经结束了）

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    _str = textField.text;
    
    return YES;
}


- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    NSLog(@"%@",_str);
    
}





@end
